package com.woniuxy.propertyjava.service.impl;

import com.woniuxy.propertyjava.entity.Housinginformation;
import com.woniuxy.propertyjava.entity.PageBean;
import com.woniuxy.propertyjava.entity.Tenancyagreement;
import com.woniuxy.propertyjava.dao.TenancyagreementDao;
import com.woniuxy.propertyjava.service.TenancyagreementService;
import org.springframework.stereotype.Service;


import javax.annotation.Resource;

/**
 * (Tenancyagreement)表服务实现类
 *
 * @author makejava
 * @since 2022-07-08 17:23:29
 */
@Service("tenancyagreementService")
public class TenancyagreementServiceImpl implements TenancyagreementService {
    @Resource
    private TenancyagreementDao tenancyagreementDao;

    /**
     * 通过ID查询单条数据
     *
     * @param tacid 主键
     * @return 实例对象
     */
    @Override
    public Tenancyagreement queryById(Integer tacid) {
        return this.tenancyagreementDao.queryById(tacid);
    }

    /**
     * 分页查询
     *
     * @param tenancyagreement 筛选条件
     * @ pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public PageBean<Tenancyagreement> queryByPage(Tenancyagreement tenancyagreement,int pageIndex,int pageSize) {
        PageBean<Tenancyagreement> pageBean=new PageBean<>();
        pageBean.setBeanList(tenancyagreementDao.queryAllByLimit(tenancyagreement, pageIndex, pageSize));
        pageBean.setPageIndex(pageIndex);
        pageBean.setPageSize(pageSize);
        pageBean.setTotalRecode(tenancyagreementDao.count(tenancyagreement));
        return pageBean;
    }

    /**
     * 新增数据
     *
     * @param tenancyagreement 实例对象
     * @return 实例对象
     */
    @Override
    public Tenancyagreement insert(Tenancyagreement tenancyagreement) {
        this.tenancyagreementDao.insert(tenancyagreement);
        return tenancyagreement;
    }

    /**
     * 修改数据
     *
     * @param tenancyagreement 实例对象
     * @return 实例对象
     */
    @Override
    public Tenancyagreement update(Tenancyagreement tenancyagreement) {
        this.tenancyagreementDao.update(tenancyagreement);
        return this.queryById(tenancyagreement.getTacid());
    }

    /**
     * 通过主键删除数据
     *
     * @param tacid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer tacid) {
        return this.tenancyagreementDao.deleteById(tacid) > 0;
    }
}
